package com.android.settings.audio.peq.peq.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.settings.R;
import com.android.settings.audio.peq.skin.SkinManager;
import com.android.settings.audio.peq.util.NameString;

import java.util.ArrayList;
import java.util.List;

public class DialogAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> mItems = new ArrayList<String>();
    private LayoutInflater mInflater;
    private boolean isShowingPlaylist = false;
    private boolean isShowLine_end = false;
    private boolean isShowLeft_ic = true;

    // private int pics[] = { R.drawable.add, R.drawable.sc,
    // R.drawable.close_img,
    // R.drawable.sx, R.drawable.batch_add };

    public DialogAdapter(Context c, List<String> Items) {
        super();

        mContext = c;

        mItems = Items;
        mInflater = LayoutInflater.from(c);
        this.isShowingPlaylist = false;

    }

    public DialogAdapter(Context c, List<String> Items,
                         boolean isShowingPlaylist) {
        super();

        mContext = c;
        mItems = Items;
        mInflater = LayoutInflater.from(c);
        this.isShowingPlaylist = isShowingPlaylist;
    }

    public DialogAdapter(Context c, List<String> Items,
                         boolean isShowingPlaylist, boolean isShowLine_end) {
        super();

        mContext = c;
        mItems = Items;
        mInflater = LayoutInflater.from(c);
        this.isShowingPlaylist = isShowingPlaylist;
        this.isShowLine_end = isShowLine_end;
    }

    public DialogAdapter(Context c, List<String> Items,
                         boolean isShowingPlaylist, boolean isShowLine_end, boolean isShowLeft_ic) {
        super();

        mContext = c;
        mItems = Items;
        mInflater = LayoutInflater.from(c);
        this.isShowingPlaylist = isShowingPlaylist;
        this.isShowLine_end = isShowLine_end;
        this.isShowLeft_ic = isShowLeft_ic;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mItems.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return mItems.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.peq_item_dialog_bottom_layout, null);
        }

        String selectItem = mItems.get(position);

        TextView item = ViewHolder.get(convertView, R.id.d_item);

        ImageView img = ViewHolder.get(convertView, R.id.d_pic);
        SkinManager.get().setImageDrawable(img, R.mipmap.peq_default_playlist);
        img.setVisibility(isShowLeft_ic ? View.VISIBLE : View.GONE);
        View findViewById = convertView.findViewById(R.id.dialogadapter_line);
        if ((mItems.size() - 1) == position && !isShowLine_end) {
            findViewById.setVisibility(View.GONE);
        } else {
            findViewById.setVisibility(View.VISIBLE);
        }

        item.setText(selectItem);

        if (!isShowingPlaylist) {
            if (selectItem != null && selectItem.toString().equals(NameString.getResoucesString(mContext, R.string.peq_delete))) {
                SkinManager.get().setImageDrawable(img, R.mipmap.peq_pop_ic_delete_nor);
            } else if (selectItem != null && selectItem.equals(NameString.getResoucesString(mContext, R.string.peq_edit))) {
                SkinManager.get().setImageDrawable(img, R.mipmap.peq_icon_rename);
            } else {
                SkinManager.get().setImageDrawable(img, R.mipmap.peq_pop_ic_song_info_nor);
            }
        }
        return convertView;
    }

}
